/********************************************************
* "SWITCH.C":                                           *
* Implementation file for the STK500 SWITCH PORT driver.*
* The SWITCHES are connected to the PA pins.            *
* Henning Hargaard, 19/10 2011                          *
*********************************************************/
#include <avr/io.h>

#define MAX_SWITCH_NR 7

// Prepare the switch port
void initSwitchPort()
{
	DDRD = 0x00;
}

// Reads all switches at a time
unsigned char switchStatus()
{
	unsigned char status;
	status = ~PIND;
	return status;
}

// Returns TRUE, if the switch having the number
// "switch_nr" is activated - otherwise return FALSE
unsigned char switchOn(unsigned char switch_nr)
{
	unsigned char mask = 0b00000001;
	unsigned char activated = 0;
	
	if(!(PIND & (mask << switch_nr)))
	{
		activated = 1;
	}
	
	return activated;
}	
	

